package com.ruoyi.back.service.v3.impl

import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import com.ruoyi.app.common.id
import com.ruoyi.back.domain.v3.MyCollect
import com.ruoyi.back.mapper.MyCollectMapper
import com.ruoyi.back.service.v3.MyCollectService
import org.springframework.stereotype.Service

@Service
class MyCollectServiceImpl : MyCollectService, ServiceImpl<MyCollectMapper, MyCollect>() {
    override fun like(recordId: Long): Boolean =
        getOne(KtQueryWrapper(MyCollect::class.java)
            .eq(MyCollect::mode, 1)
            .eq(MyCollect::userId, id())
            .eq(MyCollect::recordId, recordId))
            ?.run { true }
            ?: false

    override fun collect(recordId: Long): Boolean =
        getOne(KtQueryWrapper(MyCollect::class.java)
            .eq(MyCollect::mode, 2)
            .eq(MyCollect::userId, id())
            .eq(MyCollect::recordId, recordId))
            ?.run { true }
            ?: false
}